package com.frxuexi.shop2307.user

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.entity.InfoBean
import com.frxuexi.lib_base.entity.LoginBean
import com.frxuexi.lib_base.entity.UserBean
import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.room.LoginDao
import com.frxuexi.lib_base.utils.SignLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class UserViewModel @Inject constructor(val apiService: ApiService,val loginDao: LoginDao):BaseViewModel(){

    val codeData=SignLiveData<UserBean>()
    fun sendCode(phone:String){
        httpRequest({apiService.senCode(phone)},codeData::postValue,loginError::postValue)
    }

    val loginData=SignLiveData<LoginBean>()
    val loginError=MutableLiveData<String>()
    fun login(map:Map<String,Any>){
        httpRequest({apiService.login(toBody(map))},loginData::postValue,loginError::postValue)
    }

    val registerData=SignLiveData<LoginBean>()
    fun register(map:Map<String,Any>){
        httpRequest({apiService.register(toBody(map))},registerData::postValue,loginError::postValue)
    }

    val findData=SignLiveData<Boolean>()
    fun findPass(map:Map<String,Any>){
        httpRequest({apiService.finPass(toBody(map))},findData::postValue,loginError::postValue)
    }

    val infoData=SignLiveData<InfoBean>()
    fun getInfo(){
        httpRequest({apiService.getInfo()},infoData::postValue,loginError::postValue)
    }

    val updateInfoData=SignLiveData<Any>()
    fun updateInfo(map:Map<String,Any>){
        httpRequest({apiService.updateInfo(toBody(map))},updateInfoData::postValue,loginError::postValue)
    }

    val loginRoomData=SignLiveData<Long>()
    fun loginRoom(loginBean: LoginBean){
        roomRequest({loginDao.login(loginBean)},loginRoomData::postValue,loginError::postValue)
    }
}